package yunwo.cn.yzstation.model;

import android.widget.Toast;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import yunwo.cn.yzstation.api.HttpManager;
import yunwo.cn.yzstation.api.IongoingModel;
import yunwo.cn.yzstation.api.okapi.GLCallBack;
import yunwo.cn.yzstation.bean.InventoryBean;
import yunwo.cn.yzstation.config.MyConstants;
import yunwo.cn.yzstation.view.activity.InventoryActivity;

/**
 * Created by lao on 2017/9/19.
 */
public class OngoingModer {
    InventoryActivity activity;
    IongoingModel iongoingModel;

    public OngoingModer(InventoryActivity activity, IongoingModel iongoingModel) {
        this.activity = activity;
        this.iongoingModel = iongoingModel;
    }

    public void getData(final String type, int pagenum, int pagesize) {
        Map<String, Object> map = new HashMap<>();
        map.put("trackingStatus", "5,7,8,9");

        HttpManager.hpptPostPageString(MyConstants.Inventory,pagenum,pagesize,"create_date desc",map).execute(new GLCallBack() {
            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!result.equals("")) {

                        InventoryBean.DataBean dataBean = new Gson().fromJson(result, InventoryBean.DataBean.class);
                        iongoingModel.getListDataSuccess(dataBean,type);
                    }
                }else {
                    iongoingModel.getListDataFailure();
                    Toast.makeText(activity, "请求失败"+msg, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                iongoingModel.getListDataFailure();
                Toast.makeText(activity, "请求失败", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
